<template>
	<view class="container">
		<view class="effect">
			<!-- <view class="reduceAddDay">{{reduceAddDay}}</view> -->
			<view class="count">{{attendDay}}/{{initialDay}}</view>
			<view>已消课时/总课时</view>
		</view>
		<view class="contract">
			<view class="item" v-for="(item, index) in contractList" :key="index">
				<view style="display: flex; flex-direction: column;">
					<text>{{item.name}}({{item.code}})</text>
					<text style="margin-top: 10rpx;">{{item.beginDate}}/{{item.endDate}}</text>
				</view>
				<view style="display: flex; flex-direction: column;align-items: flex-end;">
					<text>剩余请假天数:{{item.surplusLeaveDay}}</text>
					<text style="margin-top: 10rpx;">总请假天数:{{item.surplusOriginalLeaveDay}}</text>
				</view>
			</view>
		</view>
		<view class="page">
			<view v-for="(item, index) in list" :key="index" class="item">
				<view class="more">
					<view v-if="item.type === 0">普通消课</view>
					<view v-else-if="item.type === 1">合同延长</view>
					<view v-else-if="item.type === 2">入户消课</view>
					<view class="time">{{$u.timeFormat(item.created, 'yyyy-mm-dd hh:MM:ss')}}</view>
				</view>
				<view>
					{{item.effectDay}}天
				</view>
			</view>
		</view>
		<u-loadmore v-if="!emptyShow" :status="status" />
		<u-empty class="noContent" v-if="emptyShow" text="暂时没有数据哦～"  mode="list"></u-empty>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	import { getChildrenBalance } from '@/api/user.js'
	export default {
		data() {
			return {
				initialDay: 0,
				attendDay: 0,
				reduceAddDay: 0,
				list: [],
				contractList: [],
				page: -1,
				status: 'loadmore',
				emptyShow: false,
			}
		},
		computed: {
			...mapState({
				parentInfo: state => state.user.parentInfo,
			}),
		},
		onLoad() {
			this.getList(this.page + 1);
		},
		methods: {
			getList(page) {
				const params = {
					childrenId: this.parentInfo.defaultBabyId,
					pageNum: page,
					pageSize: 20
				};
				console.log(params);
				getChildrenBalance(params).then(res => {
					console.log(res);
					this.contractList = res.data.contractList;
					this.initialDay = res.data.initialDay;
					this.attendDay = res.data.attendDay;
					this.reduceAddDay = res.data.reduceAddDay;
					this.setData(res.data.page);
				})
			},
			
			setData(page) {
				if (page.last) {
					this.status = 'nomore';
				} else {
					this.status = 'loadmore';
				}
				this.page = page.number;
				if (this.page === 0) {
					this.list = page.content;
					if (this.list.length === 0) {
						this.emptyShow = true;
					}
				} else {
					this.list = this.list.concat(page.content);
				}
			},
			
			loadMore() {
				if (this.status === 'nomore') {
					return;
				}
				this.status = 'loading';
				this.getList(this.page);
			},
		}
	}
</script>

<style lang="scss">
	.container{
		display: flex;
		flex-direction: column;
		
		.effect{
			width: 300rpx;
			height: 300rpx;
			border-radius: 50%;
			border: 2rpx;
			border-color: $app-divider-color;
			border-style: solid;
			margin-top: 60rpx;
			display: flex;
			align-self: center;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			position: relative;
			
			.reduceAddDay{
				position: absolute;
				top: 70rpx;
				right: 70rpx;
				color: $app-check-color;
			}
			
			.count{
				font-size: 60rpx;
			}
			
		}
	}
	
	.contract{
		margin-top: 60rpx;
		display: flex;
		flex-direction: column;
		width: 100%;
		padding-left: 30rpx;
		padding-right: 30rpx;
		
		.item{
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			align-items: center;
			padding: 20rpx;
			border: 2rpx;
			border-color: $app-divider-color;
			border-style: solid;
			border-radius: 20rpx;
			margin-top: 10rpx;
		}
	}
	
	.page{
		margin-top: 60rpx;
		display: flex;
		flex-direction: column;
		width: 100%;
		padding-left: 30rpx;
		padding-right: 30rpx;
		
		.item{
			display: flex;
			flex-direction: row;
			align-items: center;
			padding: 20rpx;
			border: 2rpx;
			border-color: $app-divider-color;
			border-style: solid;
			border-radius: 20rpx;
			margin-top: 10rpx;
			
			.more{
				display: flex;
				flex-direction: column;
				flex: 1;
				
				.time{
					margin-top: 10rpx;
				}
			}
		}
	}

</style>
